package com.tagtraum.perf.gcviewer;



import com.google.common.base.Optional;

import java.awt.Component;
import java.text.DecimalFormat;

public abstract class View
{
  private static final String NO_CONTENT = "";
  protected static final DecimalFormat THREE_DP = new DecimalFormat("0.000");
  protected static final DecimalFormat INTEGER = new DecimalFormat("#");
  protected static final DecimalFormat AS_PERCENTAGE = new DecimalFormat("0.00%");
  protected static final DecimalFormat PERCENT = new DecimalFormat("0.00'%'");
  private String title;
  protected String infoText;

  public abstract Component buildView();

  public void reBuildView()
  {
  }

  public String getTitle()
  {
    return this.title;
  }

  protected void setTitle(String title) {
    this.title = title;
  }

  public boolean hasInfoText()
  {
    return getInfoText() != "";
  }

  public String getInfoText() {
    String filename = getClass().getSimpleName() + "_info.html";
    loadInfoText(filename);
    return this.infoText;
  }

  protected void loadInfoText(String filename) {
    if (this.infoText != null) {
      return;
    }
    Optional text = Reader.readRelativeFile(getClass(), filename);
    if (text.isPresent())
      this.infoText = ((String)text.get());
    else
      this.infoText = "";
  }
}
